package com.seata.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seata.config.CommonResult;
import com.seata.dao.OrderMapper;
import com.seata.order.po.Order;
import com.seata.order.service.OrderService;
import com.seata.order.to.OrderTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author zxx
 * @version 1.0
 * @date 2021/5/28 11:34
 */
@RestController
@RequestMapping(value = "/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderMapper orderMapper;

    @RequestMapping("/list")
    public Page<Order> list(@RequestParam("size")int size){
        Page<Order> page = new Page<>();
        page.setSize(size);
        return orderService.page(page,new QueryWrapper<Order>()
        .lambda()
                .orderByDesc(Order::getId)
        );
    }

    /**
     * 创建订单
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody OrderTo order) {
        orderService.create(order);
        return new CommonResult(order,"订单创建成功!", 200);
    }


}
